//
// Created by gogoqiu on 2021/10/18.
//

#include "MyTray.h"

BEGIN_EVENT_TABLE(MyTray, wxTaskBarIcon)
EVT_MENU(wxID_ABOUT, MyTray::OnAbout)
EVT_MENU(wxID_EXIT, MyTray::OnExit)
EVT_TASKBAR_LEFT_DOWN( MyTray::OnClickMyTray )
END_EVENT_TABLE()

wxMenu *MyTray::CreatePopupMenu()
{
    // 每次都要 new 一个新的 wxMenu
    //菜单需求
    auto *popupMenu = new wxMenu;
    popupMenu->Append(wxID_ABOUT, _("About"));
    popupMenu->AppendSeparator();
    popupMenu->Append(wxID_EXIT, _("Exit"));
    return popupMenu;
}

void MyTray::OnAbout(wxCommandEvent& event)
{
    wxMessageBox(_T("hello!"), wxT("About Tray!"), wxOK | wxICON_INFORMATION);
}

//how to quit it
void MyTray::OnExit(wxCommandEvent& event)
{
    wxExit();
}

MyTray::MyTray( wxFrame *frame ) {
    this->frame = frame;
    //Bind( wxEVT_TASKBAR_LEFT_DOWN, &MyTray::OnClickMyTray, this );
}

/*
 * 托盘化动画
//wxTaskBarIconEvent
 在菜单里注入xua
 */
void MyTray::OnClickMyTray( wxTaskBarIconEvent& event ){
    //printf("%s\n", "OnClickMyTray");
    //this->Show(true);
    if( this->frame->IsIconized() ){
        this->frame->Iconize(false );
    }
    if( this->frame->IsShown() )
        this->frame->Show(true );
    this->frame->Raise();
}